package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;

import com.ruoyi.system.domain.SysConsumer;
import jakarta.annotation.security.PermitAll;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.SysQualificationMaterial;
import com.ruoyi.system.service.ISysQualificationMaterialService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 资质材料信息Controller
 * 
 * @author ruoyi
 * @date 2025-10-27
 */
@RestController
@RequestMapping("/material")
public class SysQualificationMaterialController extends BaseController
{
    @Autowired
    private ISysQualificationMaterialService sysQualificationMaterialService;

    /**
     * 查询资质材料信息列表
     */
    @RequiresPermissions("system:material:list")
    @GetMapping("/list")
    public TableDataInfo list(SysQualificationMaterial sysQualificationMaterial)
    {
        startPage();
        List<SysQualificationMaterial> list = sysQualificationMaterialService.selectSysQualificationMaterialList(sysQualificationMaterial);
        return getDataTable(list);
    }

    /**
     * 导出资质材料信息列表
     */
    @RequiresPermissions("system:material:export")
    @Log(title = "资质材料信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysQualificationMaterial sysQualificationMaterial)
    {
        List<SysQualificationMaterial> list = sysQualificationMaterialService.selectSysQualificationMaterialList(sysQualificationMaterial);
        ExcelUtil<SysQualificationMaterial> util = new ExcelUtil<SysQualificationMaterial>(SysQualificationMaterial.class);
        util.exportExcel(response, list, "资质材料信息数据");
    }

    /**
     * 获取资质材料信息详细信息
     */
    @RequiresPermissions("system:material:query")
    @GetMapping(value = "/{qualificationMaterialId}")
    public AjaxResult getInfo(@PathVariable("qualificationMaterialId") Long qualificationMaterialId)
    {
        return success(sysQualificationMaterialService.selectSysQualificationMaterialByQualificationMaterialId(qualificationMaterialId));
    }

    /**
     * 新增资质材料信息
     */
    @RequiresPermissions("system:material:add")
    @Log(title = "资质材料信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysQualificationMaterial sysQualificationMaterial)
    {
        return toAjax(sysQualificationMaterialService.insertSysQualificationMaterial(sysQualificationMaterial));
    }

    /**
     * 修改资质材料信息
     */
    @RequiresPermissions("system:material:edit")
    @Log(title = "资质材料信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysQualificationMaterial sysQualificationMaterial)
    {
        return toAjax(sysQualificationMaterialService.updateSysQualificationMaterial(sysQualificationMaterial));
    }

    /**
     * 删除资质材料信息
     */
    @RequiresPermissions("system:material:remove")
    @Log(title = "资质材料信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{qualificationMaterialIds}")
    public AjaxResult remove(@PathVariable Long[] qualificationMaterialIds)
    {
        return toAjax(sysQualificationMaterialService.deleteSysQualificationMaterialByQualificationMaterialIds(qualificationMaterialIds));
    }

    /**
     * 资质材料审核
     */
    @PermitAll
    @Log(title = "申请", businessType = BusinessType.APPLY)
    @PostMapping("/apply")
    public AjaxResult apply(@RequestBody SysQualificationMaterial sysQualificationMaterial)
    {
        return toAjax(sysQualificationMaterialService.apply(sysQualificationMaterial));
    }
}
